/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ChooseUserMainPanel.java
 *
 * Created on 24/12/2010, 05:53:24 PM
 */

package com.kap.view.user;

import com.kap.services.user.UserDTO;
import com.kap.services.user.UserManager;
import java.util.List;


/**
 *
 * @author Julian Caicedo
 */
public class ChooseUserMainPanel extends javax.swing.JPanel {

    /** Creates new form ChooseUserMainPanel */
    public ChooseUserMainPanel() {
        initComponents();
        endInitialization();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonAccept = new javax.swing.JButton();
        jLabelUser = new javax.swing.JLabel();
        jComboBoxUser = new javax.swing.JComboBox();
        jButtonNewUser = new javax.swing.JButton();

        jButtonAccept.setText("Accept");

        jLabelUser.setText("User:");

        jButtonNewUser.setText("New User");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelUser)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonAccept, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonNewUser, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))
                    .addComponent(jComboBoxUser, 0, 230, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelUser)
                    .addComponent(jComboBoxUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonAccept)
                    .addComponent(jButtonNewUser))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAccept;
    private javax.swing.JButton jButtonNewUser;
    private javax.swing.JComboBox jComboBoxUser;
    private javax.swing.JLabel jLabelUser;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the jButtonAccept
     */
    public javax.swing.JButton getjButtonAccept() {
        return jButtonAccept;
    }

    /**
     * @return the jButtonNewUser
     */
    public javax.swing.JButton getjButtonNewUser() {
        return jButtonNewUser;
    }

    /**
     * @return the jComboBoxUser
     */
    public javax.swing.JComboBox getjComboBoxUser() {
        return jComboBoxUser;
    }

    public void clearPanel(){
        loadList();
    }

    private void endInitialization() {
        loadList();
    }

    private void loadList(){
        jComboBoxUser.removeAllItems();
        List<UserDTO> users = UserManager.getUserManager().getUsers();
        if(users.isEmpty()){
            jButtonAccept.setEnabled(false);
        }
        else{
            for(UserDTO user : users){
                jComboBoxUser.addItem(user.getName());
            }
            jComboBoxUser.setSelectedIndex(0);
        }
    }

}
